home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Icon 8.1 / mep2 / MemMon 2.0 / Samples / concord_tables.icn < prev    next >
Encoding:
Text File  |  1990-07-18  |  1.1 KB  |  62 lines  |  [TEXT/PICN]

  1. #  Concordance program using sets
  2.  
  3. global uses, lineno, width
  4.  
  5. procedure main(args)
  6.    local word, line
  7.  
  8.    width := 15                # width of word field
  9.    uses := table()
  10.    lineno := 0
  11.  
  12.    every tabulate(words())        # tabulate all the citations
  13.  
  14.    output()                # print the citations
  15.  
  16. end
  17.  
  18. #  Add line number to citations for word
  19. #
  20. procedure tabulate(word)
  21.  
  22.    /uses[word] := table()
  23.    uses[word][lineno] := 1
  24.    return
  25.  
  26. end
  27.  
  28. #  Generate words
  29. #
  30. procedure words()
  31.    local s, line
  32.  
  33.    while line := read() do {
  34.       lineno +:= 1
  35.       write(right(lineno,6),"  ",line)
  36.       map(line) ? while tab(upto(&letters)) do {
  37.          s := tab(many(&letters))
  38.          if *s < 3 then next            # skip short words
  39.          suspend s
  40.          }
  41.       }
  42.  
  43. end
  44.  
  45. #  Print the results
  46. #
  47. procedure output()
  48.    local word, line, numbers
  49.  
  50.    write()
  51.  
  52.    uses := sort(uses,3)            # sort citations
  53.    while word := get(uses) do {
  54.       line := ""
  55.       numbers := sort(get(uses),3)
  56.       while line ||:= get(numbers) || ", " do
  57.          get(numbers)            # skip marking value
  58.       write(left(word,width),line[1:-2])
  59.       }
  60.  
  61. end
  62.